
import 'package:courseapp/entity/coursedto.dart';
import 'package:courseapp/http/HttpUtils.dart';
import 'package:courseapp/page/teacher/compont/TeacherSignRecord.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';


class TeacherAllCourse extends StatefulWidget {

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return TeacherState();
  }

}

class TeacherState extends State {

  List<DataBean> courseList = [];
  Map week = {2:"周一",3:"周二",4 : "周三",5: "周四",6 :"周五"};


  @override
  void initState() {
    // TODO: implement initState
    initRequest();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return ListView.builder(itemBuilder:createWidget,
      itemCount: courseList.length,
      itemExtent: 50,
    );
  }




  Widget createWidget(BuildContext context,int index){
    DataBean dataBean = courseList[index];
    String courseName = dataBean.courseName;
    String weekDay = week[dataBean.whatDay];
    return FlatButton(
        color: Colors.white,
        padding: EdgeInsets.all(0),
        onPressed: (){
          TeacherSignState.courseId = dataBean.id;
          Navigator.of(context).push(MaterialPageRoute(builder: (context) { return TeacherSignRecord(); }));
        },
        child: DecoratedBox(
            decoration: BoxDecoration( color: Colors.white, border: Border(bottom: Divider.createBorderSide(context, color: Colors.grey),)),
            child:Container(padding: EdgeInsets.all(5) ,child: Column(children: <Widget>[
              Container(alignment: Alignment.centerLeft, child:Text("课程:$courseName")),
              Container(alignment: Alignment.centerLeft, child:Text("时间:$weekDay")),],
            )
            )
        )

    );
  }



  Future<void> initRequest() async {
    Coursedto coursedto = await HttpUtil.getInstance().postAllTeacherCourse();
    courseList.addAll(coursedto.data);
    setState(() {});
  }





}